import random
import math

class Player:
	def __init__(self):
		self.opp = 0 #The number of players.
		self.upper = 0 #The upper bound for m.
		self.avopp = 0 #The average of all reputations.
		self.selfish = 0 #The selfishness of Player.
		self.sigma = 0 #The standard deviation.
		self.chance = 0 #This will be used to determine how often to hunt or slack.
		self.decision = 'h' #Decision to hunt or slack.
	
	def hunt_choices(self, round_number, current_food, current_reputation, m, player_reputations):
        #This section defines the variables in class Player.
        global self.opp #Determines the number of players by considering the size of the array player_reputations.
        self.opp = len(player_reputations)
        
        global self.upper #Determines P(P-1), where P is the number of players.
        self.upper = self.opp*(self.opp - 1)
        		
        global self.avopp #Determines the average opponent reputation.
        self.avopp = float(sum(player_reputations)/len(player_reputations))
        
        global self.selfish #Determines the selfishness of the program.
        if self.opp > 100:
        	self.selfish = 4
        elif self.opp > 75:
        	self.selfish = 3
        elif self.opp > 50:
        	self.selfish = 2
        elif self.opp > 25
        	self.selfish = 1.5
        elif self.opp > 10
        	self.selfish = 1.25
        elif self.opp > 5
        	self.selfish = 1
        else:
        	self.selfish = 5
        
        global self.sigma #Determines the standard deviation.
        def standev(mean):
			sum = 0
			for reputation in player_reputations:
				sum += (x-mean)**2
			return math.sqrt(sum/(self.opp-1))	
		self.sigma = standev(self.avopp)
		
		global self.chance #Determines the likelihood of hunting via the normal distribution.
		def normpdf(x, mean, sd):
    		var = float(sd)**2
    		denom = (2*math.pi*var)**.5
   			num = math.exp(-(float(x)-float(mean))**2/(2*var))
   			return num/denom	
		self.chance = normpdf(m/(self.upper), self.avopp, self.sigma)
        				 
        hunt_decisions = list() #Returns the array hunt_decisions.
        global self.decision
        if round_number > 5:
        	for reputation in player_reputations:
        		var = random.random()
        		if self.chance > var*self.selfish:
        			self.decision = 'h'
        		else:
        			self.decision = 's'
        		hunt_decisions.append(self.decision)		
        else:
        	for reputation in player_reputations:
        		self.decision = 's'
        		hunt_decisions.append(self.decision)
		return hunt_decisions

    def hunt_outcomes(self, food_earnings):
        pass #Do nothing

    def round_end(self, award, m, number_hunters):
        pass #Do nothing